package com.wondedDream.controller.web;

import com.wondedDream.model.MockExam;
import com.wondedDream.model.UserMockExamRecord;
import com.wondedDream.service.MockExamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController(value = "webMockExamController")
@RequestMapping("/web/mockExams")
@Api(description = "客户端-用户模考模块")
public class UserMockExamController {

    @Autowired
    private MockExamService mockExamService;

    // 获取模考信息
    @GetMapping("/{id}")
    public MockExam getMockExamById(@PathVariable Integer id) {
        return mockExamService.getMockExamById(id);
    }

    // 获取模考列表
    @GetMapping("/byCategoryIdAndOpenId/")
    @ApiOperation(value = "根据分类id和用户openid获取当前用户模考列表")
    public List<MockExam> getMockExamsByCategoryIdAndOpenId(@RequestParam("categoryId") Integer categoryId,
                                                            @RequestParam("userOpenId") String userOpenId) {
        return mockExamService.getMockExamsByCategoryIdAndOpenId(categoryId,userOpenId);
    }


    // 点击开始考试调用
    @PostMapping("/recordMockExamAnswer")
    @ApiOperation(value = "点击开始考试-调用记录用户模考接口")
    public void recordMockExamAnswer(
            @ApiParam(value = "模考id") @RequestParam("mockExamId") Integer mockExamId,
            @ApiParam(value = "用户openid") @RequestParam("userOpenId") String userOpenId) {
        mockExamService.recordMockExamAnswer(mockExamId, userOpenId);
    }


    //提交模考成绩 保留最新一次答题结果
    @PostMapping("/submitMockExam")
    @ApiOperation(value = "提交成绩-调用记录用户模考接口")
    public void submitMockExam(@RequestBody UserMockExamRecord userMockExamRecord){
        mockExamService.submitMockExam(userMockExamRecord);
    }
}